{	Problem: http://codeforces.ru/problemset/problem/57/A
	Verdict: Accepted
}
uses math;
type p=record
    s,o:byte;
end;
var n,x1,x2,y1,y2,res1,res2,i,j:longint; a,b:p; f:boolean;
begin
{$ifdef debug}
reset(input,'input.txt');
rewrite(output,'output.txt');
{$endif}
read(n,x1,y1,x2,y2);
if x1=0 then begin
    a.s:=1;
    if y1<n/2 then a.o:=1 else a.o:=2;
end else
if x1=n then begin
    a.s:=3;
    if y1<n/2 then a.o:=1 else a.o:=2;
end else
if y1=0 then begin
    a.s:=4;
    if x1<n/2 then a.o:=1 else a.o:=2;
end else 
if y1=n then begin
    a.s:=2;
    if x1<n/2 then a.o:=1 else a.o:=2;
end;
if x2=0 then begin
    b.s:=1;
    if y2<n/2 then b.o:=1 else b.o:=2;
end else
if x2=n then begin
    b.s:=3;
    if y2<n/2 then b.o:=1 else b.o:=2;
end else
if y2=0 then begin
    b.s:=4;
    if x2<n/2 then b.o:=1 else b.o:=2;
end else 
if y2=n then begin
    b.s:=2;
    if x2<n/2 then b.o:=1 else b.o:=2;
end;
i:=a.s;
j:=b.s;
if i=j then begin
    res2:=maxlongint;
    if odd(i) then res1:=abs(y2-y1) else res1:=abs(x2-x1);
end else begin
    if i=1 then begin
        res1:=n-y1;
        res2:=y1;
    end else 
    if i=2 then begin
        res1:=n-x1;
        res2:=x1;
    end else 
    if i=3 then begin
        res1:=y1;
        res2:=n-y1;
    end else
    if i=4 then begin
        res1:=x1;
        res2:=n-x1;
    end;
    i:=i mod 4+1;
    while i<>j do begin
        inc(res1,n); 
        i:=i mod 4+1;   
    end;
    i:=a.s-1;
    if i=0 then i:=4;
    while i<>j do begin
        inc(res2,n);
        dec(i);
        if i=0 then i:=4;
    end;
    if j=1 then begin
        inc(res1,y2);
        inc(res2,n-y2);
    end else
    if j=2 then begin
        inc(res1,x2);
        inc(res2,n-x2);
    end else
    if j=3 then begin
        inc(res1,n-y2);
        inc(res2,y2);
    end else begin
        inc(res1,n-x2);
        inc(res2,x2);
    end; 
end;
write(min(res1,res2));
end. 